package com.tkm.expressions.conditions

import com.tkm.expressions.vars.KotlinVars.Companion.b

fun main() {
    var a = 2
    var c: Int

    if (a > 2) {
        c = 4
    } else {
        c = 5
    }

    //  if-else
    c = if (a > 2) 4 else 5

    //  when
    c = when {
        a > 2 -> 4
        else -> 5
    }

    c = when(a) {
        2 -> 100
        1 -> 1000
        else -> -1
    }

    val x: Any = Any()
    c = when {
        x is String -> 100
        x == 100 -> 1000
        else -> -1
    }

    c = when(val m = (Math.random() * 100).toInt()) {
        in 0..50 -> 2
        in 51..90 -> 3
        else -> -1
    }

    val b = a
    try {
        c = a / b
    } catch (e: Exception) {
        e.printStackTrace()
        c = 0
    }

    //  try-catch
    c = try {
        a / b
    } catch (e: Exception) {
        e.printStackTrace()
        -1
    }

    c = try {
        a / b
    } catch (e: ArithmeticException) {
        e.printStackTrace()
        0
    } catch (e: Exception) {
        e.printStackTrace()
        -1
    }
}
